﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Progetto
{
    public partial class NewAction_Form : Form
    {
        public NewAction_Form()
        {
            InitializeComponent();
        }

        public string insertedText { get; set; }

        private void OK_button_Click(object sender, EventArgs e) {
            if(Firewall_radioButton.Checked) {
                insertedText = "Firewall";
            }
            else if(Networks_radioButton.Checked) {
                insertedText = "Networks";
            }
            else {
                if(this.Program_textBox.Text == "" || !this.Program_textBox.Text.Contains(".exe")) {
                    MessageBox.Show("Please insert a valid path for a program.", "Attention", MessageBoxButtons.OK);
                    DialogResult = DialogResult.None;
                }
                else if(!File.Exists(this.Program_textBox.Text)) {
                    MessageBox.Show("The selected file does not exist.", "Attention", MessageBoxButtons.OK);
                    DialogResult = DialogResult.None;
                }
                else
                    insertedText = this.Program_textBox.Text;
                
            }
        }

        private void Run_radioButton_Click(object sender, EventArgs e) {
            Program_textBox.Enabled = true;
            Program_textBox.Visible = true;

            Program_button.Enabled = true;
            Program_button.Visible = true;
        }

        private void Run_radioButton_CheckedChanged(object sender, EventArgs e) {
            Program_textBox.Enabled = false;
            Program_textBox.Visible = false;

            Program_button.Enabled = false;
            Program_button.Visible = false;
        }

        private void Program_button_Click(object sender, EventArgs e) {
            if (exe_openFileDialog.ShowDialog() == DialogResult.OK) {
                string pathOfExe = exe_openFileDialog.FileName;
                if(!pathOfExe.Contains(".exe"))
                    MessageBox.Show("Please choose an executable file.", "Attention", MessageBoxButtons.OK);
                else
                    Program_textBox.Text = pathOfExe;
            }
            else
                DialogResult = DialogResult.None;

        }

    }
}